package love.yuanmengrobot.qianyugarden.service.impl;

import love.yuanmengrobot.qianyugarden.dao.ThousandLanguageDao;
import love.yuanmengrobot.qianyugarden.entity.ThousandLanguage;
import love.yuanmengrobot.qianyugarden.service.ThousandLanguageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 千语(ThousandLanguage)表服务实现类
 *
 * @author makejava
 * @since 2021-07-13 14:28:15
 */
@Service
public class ThousandLanguageServiceImpl implements ThousandLanguageService {
    @Autowired
    ThousandLanguageDao thousandLanguageDao;

    /**
     * 通过ID查询单条数据
     *
     * @param objectid 主键
     * @return 实例对象
     */
    @Override
    public ThousandLanguage queryById(String objectid) {
        return this.thousandLanguageDao.queryById(objectid);
    }
    /**
     * 通过name查询单条数据
     *
     * @param name 主键
     * @return 实例对象
     */
    @Override
    public ThousandLanguage queryByName(String name) {
        return this.thousandLanguageDao.queryByName(name);
    }
    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ThousandLanguage> queryAllByLimit(int offset, int limit) {
        return this.thousandLanguageDao.queryAllByLimit(offset, limit);
    }
    /**
     * 查询多条数据
     *
     * @param type 类别
     * @return 对象列表
     */
    @Override
    public List<ThousandLanguage> queryAllByType(String type) {
        return this.thousandLanguageDao.queryAllByType(type);
    }

    /**
     * 查询指定级别的数据
     *
     * @param popularity 查询人气级别
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ThousandLanguage> queryAllByLimitAndLevel(int popularity, int limit) {
        return this.thousandLanguageDao.queryAllByLimitAndPopularity(popularity, limit);
    }


    /**
     * 新增数据
     *
     * @param thousandLanguage 实例对象
     * @return 实例对象
     */
    @Override
    public ThousandLanguage insert(ThousandLanguage thousandLanguage) {
        this.thousandLanguageDao.insert(thousandLanguage);
        return thousandLanguage;
    }

    /**
     * 修改数据
     *
     * @param thousandLanguage 实例对象
     * @return 实例对象
     */
    @Override
    public ThousandLanguage update(ThousandLanguage thousandLanguage) {
        this.thousandLanguageDao.update(thousandLanguage);
        return this.queryById(thousandLanguage.getObjectid());
    }

    /**
     * 通过主键删除数据
     *
     * @param objectid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String objectid) {
        return this.thousandLanguageDao.deleteById(objectid) > 0;
    }
}
